<?php

	class cct_product extends ctl_product
	{
		function sendToFriend()
		{
			
			$this->begin($_SERVER["HTTP_REFERER"]);
			//商店名称
			$shopName = $this->system->getConf('system.shopname');
			//商店网址
			$shopUrl = $this->system->base_url();
			if (isset($_POST['goods']['goods_id']))
			{				
				$data = $_POST;
				$objGoods = $this->system->loadModel('goods/gimage');
				if ($aGimage = $objGoods->get_by_goods_id($_POST['goods']['goods_id']))
				{
					$randImg = array_rand($aGimage);					
					$small = explode('|',$aGimage[$randImg]['small']);					
					$data['image'] = $shopUrl.$small[0];
					/*
					foreach ($aGimage as $key => $var)
					{
						$data['image'][$key]['small'] = $shopUrl.$var['small'];
					}
					*/
				}
			}
			
			$data['shopName'] = $shopName;
			$data['shopUrl'] = $shopUrl;
			
			$type = '';
			$email = $_POST['goods']['email'];
			$actions = array('level'=>9,'label'=>'发送给好友');
			$level = $actions['level'];
			$desc = $action['label'];
			$send_method = 'email';
			//$tpl_name = 'messenger:'.$send_method.'/sendtofriend';
			$tpl_name = 'sendtofriend';		//位于CUSTOM_CORE_DIR/html中
			$title = '你的好友向你推荐一款PPT模板,快去看看吧！';

			$objMessenger = $this->system->loadModel('system/messenger');
			if ($objMessenger->_send($send_method,$tpl_name,$email,$data,$type,$title))
			{
				$this->end(true,'邮件发送成功');
			}
			else $this->end(false,'邮件发送失败');
		}

		function goodspics($goodsId,$images=array(),$imgGstr='')
		{
			$Goods=$this->system->loadModel('goods/gimage');
			$objGoods = $this->system->loadModel('trading/goods');			
			$gimg=$_POST['gimages'];
			$goodsId=$_POST['goodsId'];

			/* alone add start */
			$product_id = $_POST['product_id'];
			$aProduct = $objGoods->getFieldByProductId($product_id,array('pdt_desc'));
			if (strstr($aProduct['pdt_desc'], '动态模板'))
			{
				$aGoods = $objGoods->getFieldById($goodsId,array('dynamic_video'));
				$baseUrl = $this->system->base_url();
				$videoUrl = $baseUrl.'home/upload/video/'.$aGoods['dynamic_video'];
				$this->pagedata['videoUrl'] = $videoUrl;
				$this->__tmpl = 'product/goodsVideo.html';
			}
			/* alone add end */
			else{
				if ($gimg){
					$tmpGimg=explode(",",$_POST['gimages']);
					if ($tmpGimg){
						foreach($tmpGimg as $key => $val){
							if (!$val)
								unset($tmpGimg[$key]);
						}
						$tmpImage=$Goods->get_by_gimage_id($goodsId,$tmpGimg);
					}
				}
				else{
					$tmpImage = $Goods->get_by_goods_id($goodsId);
				}
				$this->pagedata['imgtype'] = 'spec';
				$this->pagedata['images']['gimages']=$tmpImage;
				$this->pagedata['goods'] = $objGoods->getGoods($goodsId);
				$this->__tmpl='product/goodspics.html';						
			}
			$this->output();
		}
	}
?>